package work20241226;

/**
 * @author zdl
 * @date 2024/12/26
 */
public class Demo10 {
    public static void main(String[] args) throws InterruptedException {
        //10. 编写一个程序，使用join()方法，实现线程A打印5次，然后线程B打印5次，接着线程A再次打印5次。
        Thread t1 = new Thread(() -> {
            for (int i = 1; i < 6; i++) {
                System.out.println(Thread.currentThread().getName()+"线程打印第"+i+"次");
            }
        },"A");
        Thread t2 = new Thread(() -> {
            for (int i = 1; i < 6; i++) {
                System.out.println(Thread.currentThread().getName()+"线程打印第"+i+"次");
            }
        },"B");
        t1.start();
        t1.join();
        t2.start();
        t2.join();
        t1 = new Thread(() -> {
            for (int i = 1; i < 6; i++) {
                System.out.println(Thread.currentThread().getName()+"线程打印第"+i+"次");
            }
        },"A");
        t1.start();
        t1.join();

    }
}
